package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.retention.AppRetentionCountVO;
import cn.sdormitory.retention.RetentionVO;
import cn.sdormitory.service.AppRetentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : yy
 * @date: 2024/9/11 11:22
 * @description:
 */
@RestController
@RequestMapping("/app/retention")
@Api("宿舍滞留人员登记")
public class AppRetentionController {
    @Resource
    private AppRetentionService retentionService;

    @ApiOperation("宿管查询当日登记滞留名单")
    @GetMapping("/listTodayRetention")
    public CommonResult<List<RetentionVO>> listTodayRetention(){
        return CommonResult.success(retentionService.listTodayRetention());
    }

    @ApiOperation("当日滞留学生登记")
    @GetMapping("/retentionRegister")
    public CommonResult retentionRegister(@RequestParam("studentId") Long studentId,
                                          @RequestParam("classId") Long classId,
                                          @RequestParam("registrantUser") String registrantUser){
        retentionService.retentionRegister(studentId,classId,registrantUser);
        return CommonResult.success();
    }


    @ApiOperation("删除滞留学生")
    @GetMapping("/delRetention")
    public CommonResult delRetention(@RequestParam("id") Long id){
        retentionService.delRetention(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "根据用户id查询滞留学生统计信息-仅限班主任和部门经理使用")
    @GetMapping("/getAppRetentionCount")
    public CommonResult<List<AppRetentionCountVO>> getAppRetentionCount(@RequestParam("userId") Long userId,
                                                                        @RequestParam("rq") String rq) {
        return CommonResult.success(retentionService.getAppRetentionCount(userId,rq));
    }

    @ApiOperation(value = "根据班级id查询滞留学生名单")
    @GetMapping("/getRetentionStuByClassId")
    public CommonResult<List<RetentionVO>> getRetentionStuByClassId(@RequestParam("classId") Long classId,
                                                                                @RequestParam("rq") String rq){
        List<RetentionVO> retentionVOS = retentionService.getRetentionStuByClassId(classId,rq);
        return CommonResult.success(retentionVOS);
    }
}
